﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Gaia.WebWidgets;
using Gaia.WebWidgets.HtmlFormatting;

[assembly: WebResource("Gaia.Ajax.UI.WebControls.VideoPlayers.Scripts.swfobject.js", "text/javascript")]
[assembly: WebResource("Gaia.Ajax.UI.WebControls.VideoPlayers.Scripts.SwfPlayer.js", "text/javascript")]

namespace Gaia.Ajax.UI.WebControls.VideoPlayers
{
    public class SwfPlayer : GaiaControl, IAjaxControl
    {
        private string backgroundColor = "#1a1a1a";

        public string FileName { get; set; }
        public string Width { get; set; }
        public string Height { get; set; }
        public bool AllowFullScreen { get; set; }
        public bool AutoStart { get; set; }
        public string BackgroundColor
        {
            get { return backgroundColor; }
            set { backgroundColor = value; }
        }

        protected override void RenderControlHtml(XhtmlTagFactory create)
        {
            using (create.Div(ClientID, "swf-media"))
            {
               using (create.Div(null, "swf-noUpdate"))
               {
                   using (Tag p = create.P())
                   {
                       p.WriteContent(@"The video content presented here requires JavaScript to be enabled  and the  latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by");
                       using (create.A(null, null, "http://www.macromedia.com/go/getflashplayer").WriteContent("downloading here")) { }
                   }
               }
            }
        }

        protected override void IncludeScriptFiles()
        {
            base.IncludeScriptFiles();
            Manager.Instance.AddInclusionOfFileFromResource("Gaia.Ajax.UI.WebControls.VideoPlayers.Scripts.swfobject.js", typeof(SwfPlayer), "Gaia.Extensions.SwfPlayer.browserFinishedLoading");
            Manager.Instance.AddInclusionOfFileFromResource("Gaia.Ajax.UI.WebControls.VideoPlayers.Scripts.SwfPlayer.js", typeof(SwfPlayer), "Gaia.Extensions.SwfPlayer.browserFinishedLoading");
        }

        string IAjaxControl.GetScript()
        {
            return new RegisterControl("Gaia.Extensions.SwfPlayer", ClientID)
                .AddProperty("fileName", FileName)
                .AddProperty("backgroundColor", BackgroundColor)
                .AddProperty("height", Height)
                .AddProperty("width", Width)
                .AddProperty("allowFullScreen", AllowFullScreen)
                .AddProperty("autoStart", AutoStart)
                .ToString();
        }
    }
}
